<?php

namespace app\xwam\controller;

/**
 * ProductSpecificationController 控制器
 * @version 1.0 2016-8-23 SoChishun(14507247@qq.com) Added.
 */
class ProductSpecificationController extends AppbaseController {

    /**
     * 导出数据
     * @version 1.0 2014-6-13 SoChishun Added.
     */
    public function specification_export() {
        $asearch = $this->get_specification_search_data();
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        $list = $m_brand->scope('export')->where($asearch['where'])->select();
        if (!$list) {
            return json_encode(xsfn_message(false, '找不到符合条件的记录!'));
        }
        sofn_excel_export($list);
    }

    public function specification_copy($id = 0) {
        if (!$id) {
            return json_encode(xsfn_message(false, '参数无效'));
        }
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        $m_brand->copy_specification($id);
        return json_encode(xsfn_message(true));
    }

    public function specification_list() {
        $search=input('param.');
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        $this->assign('tree', $m_brand->select_tree(array('where' => $where)));
        $this->assign('search',$search);
        return view();
    }

    public function specification_edit($id = 0, $pid = 0) {
        $data = array();
        if ($id) {
            $m_brand = new \app\xwam\model\ProductSpecificationModel();
            $data = $m_brand->find($id);
        }
        if (!$data) {
            $data = array('pid' => $pid, 'site_id' => $this->siteId);
        }
        $this->assign('data', $data);
        return view();
    }

    public function specification_edit_save() {
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        $result = $m_brand->save_specification();
        $this->dialogJump($result['status'], $result['info']);
    }

    public function get_specification_list_json() {
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        $data=$m_brand->getIdTextList($this->siteId);
        return json_encode($data);
    }

    public function get_specification_tree_json($pid = 0) {
        $options = array();
        if ($pid) {
            $options['where']['pid'] = $pid;
        }
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        $data = $m_brand->select_json_tree($options);
        return json_encode($data);
    }

    function changeStatus($id, $status) {
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        return json_encode($m_brand->changeStatus($id, $status));
    }

    function changeSort($id, $sort) {
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        return json_encode($m_brand->changeSort($id, $sort));
    }

    /**
     * specification_delete操作
     * @param string $id 主键编号
     * @version 1.0<2015-7-31 SoChishun Added.
     */
    public function specification_delete($id = '') {
        $m_brand = new \app\xwam\model\ProductSpecificationModel();
        return json_encode($m_brand->delete_specification($id));
    }
}
